﻿#include "chinese.h"
#ifndef CONFIGMANAGER_H
#define CONFIGMANAGER_H

#include <QVariantMap>

// 使用toml格式时添加
#define TOML11_PRESERVE_COMMENTS_BY_DEFAULT
#include <toml.hpp>

class ConfigManager {
public:
    ConfigManager();

public:
    bool loadConfigFile(QString configFilePath);
    bool loadConfig(QString configContent);
    bool saveConfig();

    QString getConfigFilePath() const;
    void setConfigFilePath(const QString &configPath);

public:
    QString getConfig(QString group, QString name, QString defaultValue);
    bool setConfig(QString group, QString name, QString value);

    QString getConfig(QString name, QString defaultValue);
    bool setConfig(QString name, QString value);

    bool getBoolConfig(QString group, QString name, bool defaultValue);
    bool setBoolConfig(QString group, QString name, bool value);

    bool getBoolConfig(QString name, bool defaultValue);
    bool setBoolConfig(QString name, bool value);

    long getLongConfig(QString group, QString name, long defaultValue);
    bool setLongConfig(QString group, QString name, long value);

    long getLongConfig(QString name, long defaultValue);
    bool setLongConfig(QString name, long value);

    int getIntConfig(QString group, QString name, int defaultValue);
    bool setIntConfig(QString group, QString name, int value);

    int getIntConfig(QString name, int defaultValue);
    bool setIntConfig(QString name, int value);

public:
    QString getParams(QString paramName, QString defaultValue);
    bool setParams(QString paramName, QString value);

    bool getBoolParams(QString paramName, bool defaultValue);
    bool setBoolParams(QString paramName, bool value);

    long getLongParams(QString paramName, long defaultValue);
    bool setLongParams(QString paramName, long value);

    int getIntParams(QString paramName, int defaultValue);
    bool setIntParams(QString paramName, int value);

protected:
    toml::basic_value<TOML11_DEFAULT_COMMENT_STRATEGY, std::map, std::vector> m_configRootNode;
    QString m_configFilePath;
};

#endif // CONFIGMANAGER_H
